Skip to content

GH-3667: Close input readers when ParquetRewriter setup fails - #3662

Open
anxkhn wants to merge 1 commit into
apache:masterfrom
anxkhn:patch-7
Open

GH-3667: Close input readers when ParquetRewriter setup fails#3662
anxkhn wants to merge 1 commit into
apache:masterfrom
anxkhn:patch-7

Conversation

@anxkhn

@anxkhn anxkhn commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Rationale for this change

ParquetRewriter.getFileReaders opens a TransParquetFileReader for each input
file into a local list. If opening a later file throws IOException, it is
rethrown as IllegalArgumentException without closing the readers already opened
for the earlier files, so their SeekableInputStream handles leak. A single
corrupt, missing, or permission-denied file among several valid inputs can
therefore leak the input streams opened before the partial-open failure.

What changes are included in this PR?

In getFileReaders, close the readers already opened before rethrowing, using
org.apache.parquet.util.AutoCloseables.close(...) so every reader is released
and any close failures are aggregated as suppressed exceptions on the original
IllegalArgumentException. This matches the existing cleanup idiom in the module.
The change is limited to the catch (IOException) block; the success path is
unchanged.

Are these changes tested?

Yes. A new ParquetRewriterTest case
(testInputFileReadersClosedWhenLaterInputFileFailsToOpen) supplies a valid
input file (wrapped so it records whether the stream it hands out is closed)
followed by an InputFile whose newStream() throws, asserts that constructing
the ParquetRewriter throws IllegalArgumentException, and asserts the first
reader's stream was closed. It fails on the pre-fix code (the first stream is
left open) and passes with the fix. The full ParquetRewriterTest class passes
(Tests run: 96, Failures: 0, Errors: 0).

Are there any user-facing changes?

No public API changes. On a partial-open failure while opening input files,
ParquetRewriter now closes the input streams it had already opened.

Closes #3667

@Fokko Fokko left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seams reasonable to me 👍

@wgtmac

wgtmac commented Jul 15, 2026

Copy link
Copy Markdown
Member

I would recommend creating an issue for this. Or at least do not mark it as MINOR.

@anxkhn anxkhn changed the title MINOR: Close already-opened input readers when ParquetRewriter setup fails GH-3667: Close input readers when ParquetRewriter setup fails Jul 16, 2026
@anxkhn

anxkhn commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

Created #3667 and updated the PR title and body to reference it. Thanks for the guidance.

ParquetRewriter.getFileReaders opens each input reader into a local list. If opening a later file fails, close the readers already opened before rethrowing so their input streams do not leak. Preserve close failures as suppressed exceptions on the original failure.

Add a regression test that verifies the earlier input stream is closed, using AssertJ assertions.

Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>
@anxkhn

anxkhn commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current master and updated the regression test to use AssertJ assertions as requested. I also narrowed the PR description to the partial-open failure path covered by this change. The targeted regression test passes (4 tests).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Close input readers when ParquetRewriter setup fails

4 participants